package com.jd.webapp.portal.service;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.jd.common.convention.TTResult;
import com.jd.common.util.HttpClientUtil;
import com.jd.common.util.JsonUtils;
import com.jd.webapp.portal.pojo.OrderExt;

@Service
public class OrderServiceImpl implements OrderService {
	private static final Logger logger = Logger.getLogger(OrderService.class);
	
	@Value("${ORDER_BASE_URL}")
	private String ORDER_BASE_URL;
	@Value("${ORDER_CREATE_URL}")
	private String ORDER_CREATE_URL;

	@Override
	public String createOrder(OrderExt order) {
		String objectToJson = JsonUtils.objectToJson(order);
		// 调用taotao-order的服务提交订单。
		String json = HttpClientUtil.doPostJson(ORDER_BASE_URL
				+ ORDER_CREATE_URL, objectToJson);
		
		if(logger.isDebugEnabled()){
			logger.debug(JsonUtils.objectToJson(order));
		}
		// 把json转换成taotaoResult
		TTResult taotaoResult = TTResult.formatToPojo(json,Long.class);
		if (taotaoResult.getStatus() == 200) {
			Long orderId = (Long) taotaoResult.getData();
			return orderId.toString();
		}
		return "";
	}

}
